<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${ctx}/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="${(illegal.id)!}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">违规类型</label>
        <div class="layui-input-block">
            <input type="radio" name="dictionaryValue" value="逾期" title="逾期" >
            <input type="radio" name="dictionaryValue" value="损坏" title="损坏" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">违规人</label>
        <div class="layui-input-block">
            <input type="text" name="readerName" lay-verify="required" lay-reqtext="违规人不能为空" value="${(illegal.readerName)!}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">创建人</label>
        <div class="layui-input-block">
            <input type="text" name="adminName"  value="${(illegal.adminName)!}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">违规情况</label>
        <div class="layui-input-block">
            <textarea name="illegalContent" class="layui-textarea" >${(illegal.illegalContent)!}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            <button id="closeBtn" class="layui-btn layui-btn-normal">取消提交</button>
        </div>

    </div>
</div>
<script src="${ctx}/lib/layui/layui.js" charset="utf-8"></script>
<script>
    const ctx = "${ctx}";
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        var i = '${illegal.dictionaryValue}';
        $("input:radio[value='" + i +"']").prop("checked", "checked");
        form.render();
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data);
            $.ajax({
                type: "put",
                url: ctx + "/illegal/update",
                data: {
                    id: data.field.id,
                    dictionaryValue: data.field.dictionaryValue,
                    readerName: data.field.readerName,
                    adminName: data.field.adminName,
                    illegalContent: data.field.illegalContent
                },
                success: function (data) {
                    if (data.code === 200) {
                        layer.msg("操作成功",function () {
                            const iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            parent.location.reload();
                        })
                    } else {
                        layer.msg(data.msg);
                    }
                }

            })

            return false;
        });

        /**
         * 关闭弹出层
         */
        $("#closeBtn").click(function () {
            // 先得到当前iframe层的索引
            var index = parent.layer.getFrameIndex(window.name);
            // 再执⾏关闭
            parent.layer.close(index);
        });

    });
</script>
</body>
</html>